/*
 * @lc app=leetcode.cn id=14 lang=cpp
 *
 * [14] 最长公共前缀
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
// @lc code=start
class Solution {
public:
    string longestCommonPrefix(vector<string>& strs) {
        int n = strs.size();
        string s = strs[0];
        if(n == 0) {
            return strs[0];
        }
        for(int i = 1;i < n;i++) {
            string temp;
            for(int j = 0;j < min(s.length(),strs[i].length());j++){
                if(s[j] == strs[i][j]){
                    temp.push_back(s[j]);
                }else {
                    break;
                }
            }
            s = temp;
        }
        return s;
    }
};
// @lc code=end

